Skip to content

Results with known axes open in Fiji as hyperstacks (WithAxes, result_axes_v1) - #165

Merged
guijacquemet merged 4 commits into
mainfrom
claude/keen-mendel-ekvei7
Nov 17, 2026
Merged

guijacquemet merged 4 commits into
mainfrom
claude/keen-mendel-ekvei7

Conversation

@guijacquemet

Copy link
Copy Markdown
Contributor

Problem. A tool's 4D result, such as Fast4DRegPy's corrected time-lapse, opened in Fiji as one long stack (T × Z slices). The worker wrote every result as plain TIFF pages, and Fiji doesn't know what each dimension is.

Change

  • WithAxes(array, axes): a tool whose output axes depend on its input can return them at run time, e.g. return WithAxes(corrected, "TZYX"). They're checked: letters from T C Z Y X S, one per dimension, and the same as a declared Axes if there is one.

  • When a result is written as an ImageJ hyperstack. All of these must hold:

    • its axes are known (declared Axes or WithAxes);
    • the axes are in ImageJ order (a subsequence of T Z C Y X ending in Y X);
    • no dimension has size 1;
    • the pixel type is one ImageJ stores (uint8, uint16, int16, float32);
    • it's smaller than 4 GiB.

    Fiji's own reader then shows time points, slices and channels. The array is never reordered, so tifffile.imread returns the same array, and napari, notebooks and the case runner see what they saw before.

  • Everything else is written as before, including 4D results without known axes (the CZYX default is a guess and must not decide how Fiji shows a time-lapse).

  • Feature result_axes_v1, version 0.3.0a4; PROTOCOL, AUTHORING, CAPABILITIES and HOST_FEATURES updated. No change to the napari, Fiji or QuPath plugins.

Independent review. A separate agent reviewed the first commit and found a real bug: ImageJ can't record a T, Z or C of size 1, so a single-slice or single-time-point result (even with only a declared Axes) came back without that dimension. The second commit fixes it (size-1 dimensions and ≥ 4 GiB results are written as before). It also replaces a test that couldn't fail, and adds round-trip matrix cases as docs/TESTING.md asks.

Tests

  • tests/test_result_axes.py, 17 tests: hyperstack metadata and identical read-back for TYX, TZYX, ZCYX, CYX and TZCYX in each pixel type; size-1 dimensions (6 sub-cases fail without the fix); labels; booleans; declared Axes only; the size limit; and the refusals.
  • Round-trip matrix: tool echo_image_with_axes, 44 cases (11 shapes, size-1 ones included, × 4 dtypes) across worker, CLI, snippet and notebook.
  • black, ruff, mypy, vulture and the annotation check are clean.

Checked in Fiji (IJ.openImage, Fiji 2.18): TZYX 4 × 6 opens as a hyperstack with 6 slices × 4 frames, ZCYX as 3 channels × 6 slices, TYX as 5 frames, CYX as 3 channels. A 4D result without axes still opens as 24 slices.

Host check. Fast4DRegPy's tools return their results with WithAxes, falling back to plain arrays on older Tools (separate PR in Fast4DRegPy). Its napari and Fiji UI audits run against this branch. There's no Playground tool: WithAxes is a return wrapper, not a declared type, and it's covered by the matrix tool above and the Fast4DRegPy audit.

Release. After merge, the maintainer creates v0.3.0-alpha.4; a template PR then moves LC_TOOLS_PIN.


Generated by Claude Code

…_axes_v1)

A corrected time-lapse came back to Fiji as one long stack (T x Z
slices), because the worker wrote every result as plain TIFF pages.
Now an image/labels result whose axes are known, declared with Axes or
returned with the new WithAxes(array, axes), is written as an ImageJ
hyperstack when its axes are in ImageJ order (a subsequence of
T Z C Y X ending in Y X) and its pixel type is one ImageJ stores
(uint8, uint16, int16, float32). The array is never reordered: tifffile
reads back the same array, so napari, notebooks and the case runner see
what they saw before. Unknown axes (the CZYX default guess for 4D) and
any other order are written as before. WithAxes axes are checked
(letters, one per dimension, the same as a declared Axes).

Feature result_axes_v1, version 0.3.0a4. Checked with Fiji's own reader:
TZYX opens as slices x frames, ZCYX as channels x slices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Scma6VXx7mT1FYsKmB1184
Independent review found that ImageJ cannot record a T, Z or C of size
1, so tifffile read a single-slice or single-time-point result back
without that dimension, also for a tool that only declares Axes(...):
(3, 1, Y, X) TZYX came back as (3, Y, X). Such results, and results of
4 GiB or more (an ImageJ TIFF is never a BigTIFF), are now written as
before.

Tests: size-1 dimensions (fail without the fix), labels, booleans,
declared Axes alone, the size limit; the pixel-type fallback now uses a
type portable_dtype keeps (big-endian uint16). The round-trip matrix
gets the tool echo_image_with_axes and 44 cases (11 shapes, size-1 ones
included, x 4 dtypes) that check the array read back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Scma6VXx7mT1FYsKmB1184
Found by the independent re-review: the test pins the exact list of
feature ids.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Scma6VXx7mT1FYsKmB1184
The test pins the exact list of ids (run records have none of their
own); result_axes_v1 is about result files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Scma6VXx7mT1FYsKmB1184
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants